#pragma once

#include "noncopyable.h"
#include "InetAddress.h"

class Socket : noncopyable
{
public:
  explicit Socket(int sockfd)
    : m_sockfd(sockfd)
  {}
  ~Socket();
  void bindAddress(const InetAddress &localAddress);
  void listen();
  int accept(InetAddress* peerAddress);
  void shutdownWrite();
  ///
  /// Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).
  ///
  void setTcpNoDelay(bool on);

  ///
  /// Enable/disable SO_REUSEADDR
  ///
  void setReuseAddr(bool on);

  ///
  /// Enable/disable SO_REUSEPORT
  ///
  void setReusePort(bool on);

  ///
  /// Enable/disable SO_KEEPALIVE
  ///
  void setKeepAlive(bool on);
  int fd() { return m_sockfd; }
private:
  const int m_sockfd;
};